package com.star.markdown;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;

public class App {
    public static void main(String[] args) {
        if (args != null && args.length > 1) {
            String option = args[0];
            if (!"-h".equalsIgnoreCase(option) && !"-html".equalsIgnoreCase(option)) {
                showUsage();
            } else {
                String projectPath = System.getProperty("user.dir");
                String mdPath = projectPath + "\\" + args[1];
                String htmlPath = null;
                if (args.length >= 3) {
                    htmlPath = args[2];
                } else {
                    htmlPath = mdPath.replace(".md", ".html");
                }

                try {
                    MarkdownUtils.toHtml(mdPath, htmlPath);
                } catch (IOException var5) {
                    var5.printStackTrace();
                }

            }
        } else {
            showUsage();
        }
    }

    private static void showUsage() {
        String usage = "使用方法：\n" +
                "  [option] 参数...\n" +
                "  \n" +
                "  option:\n" +
                "  \t-h:\t或者-html。\n" +
                "  \t\t后面跟 参数1，参数2。\n" +
                "  \t\t参数1代表 要转换的md文件名称，参数2为转换后的文件名称。\n" +
                "  \t\t参数2可不填，如果不填默认生成在当前文件夹下，名称和md文件相同。";
        System.out.println(usage);
    }

    private static String getText(String src) throws IOException {
        InputStream fis = null;
        ByteArrayOutputStream baos = null;

        try {
            baos = new ByteArrayOutputStream();
            fis = App.class.getResourceAsStream(src);
            byte[] buffer = new byte[1024];

            int len;
            while ((len = fis.read(buffer)) != -1) {
                baos.write(buffer, 0, len);
            }

            String text = baos.toString();
            String var7 = text;
            return var7;
        } finally {
            closeIO(fis);
            closeIO(baos);
        }
    }

    private static void closeIO(Closeable io) {
        if (io != null) {
            try {
                io.close();
            } catch (IOException var2) {
                var2.printStackTrace();
            }

            io = null;
        }

    }
}